import {defineStore} from "pinia";
import {ref} from "vue"
import {addPrivateAPI, delPrivateAPI, modifyPrivateAPI, detailPrivateAPI, listPrivateAPI} from "@/apis/api.js";

export const useAPIStore = defineStore('api', () => {
    const apiList = ref([])

    // 增
    const addAPI = async (data) => {
        const res = await addPrivateAPI(data)
        return res.data
    }

    // 删
    const delAPI = async (data) => {
        const res = await delPrivateAPI(data)
        return res.data
    }

    // 改
    const modifyAPI = async (data) => {
        const res = await modifyPrivateAPI(data)
        return res.data
    }

    // 查单个
    const detailAPI = async (data) => {
        const res = await detailPrivateAPI(data)
        return res.data.data
    }

    // 查全部
    const listAPI = async () => {
        const res = await listPrivateAPI()
        apiList.value = res.data.data
    }

    return {
        apiList, addAPI, delAPI, modifyAPI, detailAPI, listAPI
    }
})